package com.xxx.controller;


import com.xxx.pojo.Position;
import com.xxx.pojo.RespBean;
import com.xxx.service.IPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 *  岗位管理的增删改查
 * </p>
 *
 * @author WXH
 * @since 2022-02-23
 */
@Api(value = "岗位管理",tags = "岗位管理")
@RestController
@RequestMapping("/system/basic/positon")
public class PositionController {
    @Autowired
    private IPositionService positionService;

    @ApiOperation(value = "获取所有岗位信息")
    @GetMapping("/list")
    public List<Position> getAllPositions(){
        return positionService.list();
    }

    @ApiOperation(value = "添加岗位信息")
    @PostMapping("/add")
    public RespBean addPosition(@RequestBody  Position position){
        position.setCreateDate(LocalDateTime.now());
        if(positionService.save(position)){
            return RespBean.sucess("添加成功");
        }
        return RespBean.error("更新失败");
    }
    @ApiOperation(value = "更新岗位信息")
    @PutMapping("/update")
    public RespBean updatePosition(Position position){
        if(positionService.updateById(position)){
            return RespBean.sucess("更新成功");
        }
        return RespBean.error("更新失败");
    }
    @ApiOperation(value = "删除岗位信息")
    @DeleteMapping("/delete")
    public RespBean deletePosition(@RequestParam("id") Integer id){
        if (positionService.removeById(id)){
            return RespBean.sucess("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @ApiOperation( value = "批量删除岗位信息")
    @DeleteMapping("/deletes")
    public RespBean deletePositionByIds(@RequestParam Integer[] ids){
        if (positionService.removeByIds(Arrays.asList(ids))){
            return RespBean.sucess("删除成功！！");
        }
        return RespBean.error("删除失败");
    }
}
